/**
 * @version 2007-5-9
 * @author xalinx at gmail dot com
 */
package org.nanhill.support.spring.dbutil;

import java.io.Serializable;

import javax.sql.DataSource;

import org.nanhill.commons.dbutil.builder.SqlBuilder;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

/**
 * @version 2007-5-9
 * @author xalinx at gmail dot com
 * 
 */
public class DaoSupport<E, ID extends Serializable> extends JdbcDaoSupport {

	@Override
	protected JdbcTemplate createJdbcTemplate(DataSource dataSource) {
		return new DaoTemplate(dataSource);
	}

	private SimpleDaoTemplate simpleDaoTemplate;

	/**
	 * Create a SimpleJdbcTemplate based on the configured JdbcTemplate.
	 */
	@Override
	protected void initTemplateConfig() {
		this.simpleDaoTemplate = new SimpleDaoTemplate(getJdbcTemplate());
		this.simpleDaoTemplate.setSqlBuilder(sqlBuilder);
	}

	/**
	 * Return a SimpleJdbcTemplate wrapping the configured JdbcTemplate.
	 */
	protected SimpleDaoTemplate getSimpleDaoTemplate() {
		return simpleDaoTemplate;
	}

	private SqlBuilder sqlBuilder;

	public void setSqlBuilder(SqlBuilder builder) {
		this.sqlBuilder = builder;
		initTemplateConfig();
	}

}
